import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Labyrinth1 here.
 * 
 * @author Paola Valle Pazos y Sonia Estefania Monasterio Ochoa
 * @version laberinto para el primer nivel
 */
public class Labyrinth1 extends World
{
    public static final int TAM_BLOQUE = 10;
    public static final int NUM_REN = 60;
    public static final int NUM_COL = 80;
    private Hero hero;    
    GreenfootSound cancion;
    
    private int vidas;
    private int coins;
    
    private SimpleTimer timer = new SimpleTimer();    
    private Counter contTimer = new Counter("timer: ");
    private Counter score;// = new Counter("puntos: ");
    private Counter lifes;// = new Counter("vidas: ");
    
    /**
     * Constructor for objects of class Labyrinth.
     * 
     */
    public Labyrinth1()
    {                   
        super(NUM_COL, NUM_REN, TAM_BLOQUE);
        
        timer.mark();        
        
        cancion= new GreenfootSound("Legend of Zelda_ All Ocarina Songs [OoT & MM] [HD].mp3");
        hero = new Hero();
        addObject(hero, 5, 54);
        
        prepare(0);
    }
    
    public void act()
    {
        cancion.playLoop();
        contadores();
        controlTimer();
    }
    
    public void contadores()
    {
        vidas = ((Hero)this.getObjects(Hero.class).get(0)).regresaVidas();
        coins = ((Hero)this.getObjects(Hero.class).get(0)).regresaPuntos();                
        
        score = new Counter("puntos: ");
        score.setValue(coins-1);        
        
        lifes = new Counter("vidas: ");
        lifes.setValue(vidas-1);
        
        addObject(score, 7, 1);
        addObject(lifes, 71, 1);
        
        score.setValue(score.getValue()+1);
        lifes.setValue(lifes.getValue()+1);
    }
    
    //control timer    
    public int controlTimer()
    {                                    
        addObject(contTimer, 18, 1);
        
       if(timer.millisElapsed() >= 1000)
       {
            timer.mark(); // Reset the timer
            contTimer.setValue(contTimer.getValue() + 1);                    
            System.out.println(contTimer.getValue());            
       }
       
       return contTimer.getValue();
    }
    
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    public void prepare(int nivel)
    {        
        switch(nivel)
        {
            case 0:            
            nivel1();
            break;
            case 1:
            nivel2();
            break;
            case 2:
            nivel3();
            break;
        }
       
        WallH wallh18 = new WallH();
        addObject(wallh18, 73, 2);
        wallh18.setLocation(73, 1);
        wallh18.setLocation(73, 1);
        WallH wallh19 = new WallH();
        addObject(wallh19, 5, 59);
        wallh19.setLocation(5, 58);                 
    }
    
    public void nivel1()
    {                
        WallV wallv1 = new WallV();
        addObject(wallv1, 1, 52);
        WallV wallv2 = new WallV();
        addObject(wallv2, 1, 36);
        WallV wallv3 = new WallV();
        addObject(wallv3, 1, 20);        
        WallV wallv4 = new WallV();
        addObject(wallv4, 1, 4);
        WallV wallv5 = new WallV();
        addObject(wallv5, 78, 52);
        WallV wallv6 = new WallV();
        addObject(wallv6, 78, 36);
        WallV wallv7 = new WallV();
        addObject(wallv7, 78, 20);        
        WallV wallv8 = new WallV();
        addObject(wallv8, 78, 4);

        WallH wallh1 = new WallH();
        addObject(wallh1, 68, 58);
        WallH wallh2 = new WallH();
        addObject(wallh2, 52, 58);
        WallH wallh3 = new WallH();
        addObject(wallh3, 36, 58);
        WallH wallh4 = new WallH();
        addObject(wallh4, 20, 58);
        WallH wallh5 = new WallH();
        addObject(wallh5, 59, 1);
        WallH wallh6 = new WallH();
        addObject(wallh6, 43, 1);
        WallH wallh7 = new WallH();
        addObject(wallh7, 27, 1);
        WallH wallh8 = new WallH();
        addObject(wallh8, 11, 1);
        WallV wallv9 = new WallV();
        addObject(wallv9, 10, 52);
        WallV wallv10 = new WallV();
        addObject(wallv10, 69, 7);

        WallV wallv19 = new WallV();
        addObject(wallv19, 69, 7);
        WallV wallv20 = new WallV();
        addObject(wallv20, 10, 52);
        WallH wallh9 = new WallH();
        addObject(wallh9, 20, 46);
        WallH wallh10 = new WallH();
        addObject(wallh10, 16, 38);
        WallV wallv11 = new WallV();
        addObject(wallv11, 10, 28);
        WallV wallv12 = new WallV();
        addObject(wallv12, 30, 44);
        WallV wallv13 = new WallV();
        addObject(wallv13, 22, 28);
        WallH wallh11 = new WallH();
        addObject(wallh11, 16, 12);
        WallH wallh12 = new WallH();
        addObject(wallh12, 33, 27);
        wallh12.setLocation(32, 27);
        wallh12.setLocation(32, 26);
        WallV wallv14 = new WallV();
        addObject(wallv14, 38, 36);
        WallH wallh13 = new WallH();
        addObject(wallh13, 44, 45);
        WallV wallv15 = new WallV();
        addObject(wallv15, 50, 36);
        WallV wallv16 = new WallV();
        addObject(wallv16, 50, 20);
        WallH wallh14 = new WallH();
        addObject(wallh14, 40, 14);
        WallH wallh15 = new WallH();
        addObject(wallh15, 53, 10);
        WallH wallh16 = new WallH();
        addObject(wallh16, 60, 23);
        WallV wallv17 = new WallV();
        addObject(wallv17, 62, 33);
        WallH wallh17 = new WallH();
        addObject(wallh17, 65, 50);
        WallV wallv18 = new WallV();
        addObject(wallv18, 66, 40);
        wallh17.setLocation(64, 50);
        removeObject(wallh17);

        Heart heart = new Heart();
        addObject(heart, 44, 40);
        MasterSword mastersword = new MasterSword();
        addObject(mastersword, 16, 33);
        Coin coin = new Coin();
        addObject(coin, 73, 53);
        Coin coin2 = new Coin();
        addObject(coin2, 57, 29);
        Coin coin3 = new Coin();
        addObject(coin3, 40, 9);
        Coin coin4 = new Coin();
        addObject(coin4, 17, 53);
        Coin coin5 = new Coin();
        addObject(coin5, 6, 7);
        Ghost ghost = new Ghost();
        addObject(ghost, 73, 19);
        Vampire vampire = new Vampire();
        addObject(vampire, 39, 51);
        Witch witch = new Witch();
        addObject(witch, 33, 20);
                       
        Door door = new Door();
        addObject(door, 73, 6);
    }
    
    public void nivel2()
     {
         WallV wallv1 = new WallV();
        addObject(wallv1, 1, 52);
        WallV wallv2 = new WallV();
        addObject(wallv2, 1, 36);
        WallV wallv3 = new WallV();
        addObject(wallv3, 1, 20);        
        WallV wallv4 = new WallV();
        addObject(wallv4, 1, 4);
        WallV wallv5 = new WallV();
        addObject(wallv5, 78, 52);
        WallV wallv6 = new WallV();
        addObject(wallv6, 78, 36);
        WallV wallv7 = new WallV();
        addObject(wallv7, 78, 20);        
        WallV wallv8 = new WallV();
        addObject(wallv8, 78, 4);

        WallH wallh1 = new WallH();
        addObject(wallh1, 68, 58);
        WallH wallh2 = new WallH();
        addObject(wallh2, 52, 58);
        WallH wallh3 = new WallH();
        addObject(wallh3, 36, 58);
        WallH wallh4 = new WallH();
        addObject(wallh4, 20, 58);
        WallH wallh5 = new WallH();
        addObject(wallh5, 59, 1);
        WallH wallh6 = new WallH();
        addObject(wallh6, 43, 1);
        WallH wallh7 = new WallH();
        addObject(wallh7, 27, 1);
        WallH wallh8 = new WallH();
        addObject(wallh8, 11, 1);

        WallV wallv11 = new WallV();
        addObject(wallv11, 10, 36);
        WallH wallh9 = new WallH();
        addObject(wallh9, 16, 26);
        WallV wallv12 = new WallV();
        addObject(wallv12, 22, 36);
        WallH wallh10 = new WallH();
        addObject(wallh10, 28, 46);
        WallV wallv13 = new WallV();
        addObject(wallv13, 34, 36);
        WallV wallv14 = new WallV();
        addObject(wallv14, 10, 11);
        WallH wallh11 = new WallH();
        addObject(wallh11, 20, 13);
        WallV wallv15 = new WallV();
        addObject(wallv15, 30, 15);
        WallV wallv16 = new WallV();
        addObject(wallv16, 69, 27);
        WallH wallh12 = new WallH();
        addObject(wallh12, 63, 17);
        WallH wallh13 = new WallH();
        addObject(wallh13, 51, 13);
        WallV wallv17 = new WallV();
        addObject(wallv17, 45, 23);
        WallH wallh14 = new WallH();
        addObject(wallh14, 44, 42);
        WallV wallv18 = new WallV();
        addObject(wallv18, 54, 40);
        WallH wallh15 = new WallH();
        addObject(wallh15, 52, 50);
        WallV wallv19 = new WallV();
        addObject(wallv19, 65, 35);

        Coin coin = new Coin();
        addObject(coin, 73, 53);
        Coin coin2 = new Coin();
        addObject(coin2, 57, 29);
        Coin coin3 = new Coin();
        addObject(coin3, 40, 9);
        Coin coin4 = new Coin();
        addObject(coin4, 17, 53);
        Coin coin5 = new Coin();
        addObject(coin5, 6, 7);
        Ghost ghost = new Ghost();
        addObject(ghost, 73, 19);
        Vampire vampire = new Vampire();
        addObject(vampire, 39, 51);
        Witch witch = new Witch();
        addObject(witch, 33, 20);
        Door2 door2 = new Door2();
        addObject(door2, 73, 3);
        Heart heart = new Heart();
        addObject(heart, 29, 40);
        MasterSword mastersword = new MasterSword();
        addObject(mastersword, 52, 18);
        Ghost ghost1 = new Ghost();
        addObject(ghost1, 6, 22);
      }
    
    public void nivel3()
    {
        Castle castle = new Castle();
        addObject(castle, 73, 3);

        WallV wallv = new WallV();
        addObject(wallv, 2, 7);
        WallV wallv2 = new WallV();
        addObject(wallv2, 3, 23);
        WallV wallv3 = new WallV();
        addObject(wallv3, 4, 39);
        WallV wallv4 = new WallV();
        addObject(wallv4, 4, 54);
        WallV wallv5 = new WallV();
        addObject(wallv5, 79, 8);
        WallV wallv6 = new WallV();
        addObject(wallv6, 79, 24);
        WallV wallv7 = new WallV();
        addObject(wallv7, 79, 40);
        WallV wallv8 = new WallV();
        addObject(wallv8, 79, 57);
        WallV wallv9 = new WallV();
        addObject(wallv9, 17, 42);
        WallV wallv10 = new WallV();
        addObject(wallv10, 17, 27);
        WallH wallh = new WallH();
        addObject(wallh, 12, 2);
        WallH wallh2 = new WallH();
        addObject(wallh2, 28, 2);
        WallH wallh3 = new WallH();
        addObject(wallh3, 44, 2);
        WallH wallh4 = new WallH();
        addObject(wallh4, 60, 2);
        WallH wallh5 = new WallH();
        addObject(wallh5, 24, 17);
        WallH wallh6 = new WallH();
        addObject(wallh6, 51, 18);
        WallH wallh7 = new WallH();
        addObject(wallh7, 33, 34);
        WallH wallh8 = new WallH();
        addObject(wallh8, 70, 59);
        WallH wallh9 = new WallH();
        addObject(wallh9, 55, 59);
        WallH wallh10 = new WallH();
        addObject(wallh10, 43, 59);
        WallH wallh11 = new WallH();
        WallH wallh12 = new WallH();
        addObject(wallh12, 28, 59);
        WallH wallh13 = new WallH();
        addObject(wallh13, 36, 49);
        WallH wallh14 = new WallH();
        addObject(wallh14, 64, 50);
        WallH wallh15 = new WallH();
        addObject(wallh15, 70, 34);
        wallv.setLocation(1, 7);
        wallh.setLocation(11, 1);
        wallh2.setLocation(27, 1);
        wallh3.setLocation(43, 1);
        wallh4.setLocation(59, 1);
        wallv5.setLocation(79, 7);
        wallv6.setLocation(79, 23);
        wallv7.setLocation(79, 39);
        wallv8.setLocation(79, 55);
        wallh8.setLocation(72, 59);
        wallh9.setLocation(56, 59);
        wallh10.setLocation(40, 59);
        wallh12.setLocation(24, 59);
        wallv2.setLocation(1, 23);
        wallv3.setLocation(1, 39);
        wallv4.setLocation(1, 55);
        wallh5.setLocation(23, 17);
        wallv10.setLocation(12, 27);
        wallv9.setLocation(12, 43);
        wallh5.setLocation(18, 17);
        wallh5.setLocation(18, 12);
        wallv10.setLocation(12, 22);
        wallv9.setLocation(12, 38);
        wallh6.setLocation(46, 12);
        wallh7.setLocation(22, 30);
        wallh13.setLocation(32, 44);
        wallh15.setLocation(72, 29);
        wallh14.setLocation(56, 29);
        WallV wallv11 = new WallV();
        addObject(wallv11, 70, 21);
        WallV wallv12 = new WallV();
        addObject(wallv12, 50, 36);
        WallV wallv13 = new WallV();
        addObject(wallv13, 26, 51);
        WallV wallv14 = new WallV();
        addObject(wallv14, 39, 28);
        WallV wallv15 = new WallV();
        addObject(wallv15, 65, 45);
        WallV wallv16 = new WallV();
        addObject(wallv16, 33, 12);
        WallV wallv17 = new WallV();
        addObject(wallv17, 60, 11);
        wallv13.setLocation(26, 50);
        wallv13.setLocation(26, 52);
        wallh13.setLocation(32, 46);
        wallv12.setLocation(50, 35);
        wallv11.setLocation(70, 22);
        wallv16.setLocation(32, 11);
        wallv14.setLocation(38, 39);
        WallH wallh16 = new WallH();
        addObject(wallh16, 59, 51);
        WallH wallh17 = new WallH();
        addObject(wallh17, 39, 21);
        WallH wallh18 = new WallH();
        addObject(wallh18, 19, 46);
        wallh18.setLocation(18, 46);
        wallh17.setLocation(38, 21);

        Ghost ghost3 = new Ghost();
        addObject(ghost3, 7, 8);
        Ghost ghost4 = new Ghost();
        addObject(ghost4, 74, 36);
        Vampire vampire2 = new Vampire();
        addObject(vampire2, 18, 40);
        Vampire vampire3 = new Vampire();
        addObject(vampire3, 34, 54);
        Witch witch2 = new Witch();
        addObject(witch2, 39, 8);
        Witch witch3 = new Witch();
        addObject(witch3, 44, 27);
        Heart heart2 = new Heart();
        addObject(heart2, 75, 25);
        MasterSword mastersword2 = new MasterSword();
        addObject(mastersword2, 33, 41);
        Coin coin6 = new Coin();
        addObject(coin6, 72, 54);
        Coin coin7 = new Coin();
        addObject(coin7, 60, 46);
        Coin coin8 = new Coin();
        addObject(coin8, 22, 26);
        Coin coin9 = new Coin();
        addObject(coin9, 26, 6);
        Coin coin10 = new Coin();
        addObject(coin10, 55, 6);
    }
    
    public void stopped()
    {
        super.stopped();
        cancion.pause();
    }
    
    public void started()
    {
        super.started();
        cancion.setVolume(50);       
    }        
    
    public Counter getCounter(){return score;}
    public Counter getLifes(){return lifes;}
}
    